package com.atguigu.lease.web.admin.controller;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.model.enums.AppointmentStatus;
import com.atguigu.lease.web.admin.service.ViewAppointmentService;
import com.atguigu.lease.web.admin.vo.appointment.AppointmentQueryVo;
import com.atguigu.lease.web.admin.vo.appointment.AppointmentVo;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 李壮
 * @CreateTime: 2025-05-12
 * @Version: 1.0
 */

@RestController
@RequestMapping("/admin/appointment")
@Tag(name = "预约看房管理")
public class ViewAppointmentController {

    @Autowired
    ViewAppointmentService viewAppointmentService;

    @Operation(summary = "根据id更新预约状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam AppointmentStatus status){
        LambdaUpdateWrapper<ViewAppointment> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(ViewAppointment::getId,id);
        lambdaUpdateWrapper.set(ViewAppointment::getAppointmentStatus,status);
        viewAppointmentService.update(lambdaUpdateWrapper);
        return Result.ok();
    }

    @Operation(summary = "根据条件分页查询预约信息")
    @GetMapping("/page")
    public Result page(@RequestParam Long current, @RequestParam Long size, AppointmentQueryVo appointmentQueryVo){
        IPage<AppointmentVo> page = new Page<>(current,size);
        IPage<AppointmentVo> list = viewAppointmentService.qageAppointmentByQuery(page,appointmentQueryVo);
        return Result.ok(list);

    }
}
